#include "GameOpt.h"


void WaitForEnter()
{    
	int  ch1;
    
    ch1 = -1;
	while(ch1!=13)
	{
		if (_kbhit())					/* check for a keystroke */
		{
			ch1 = _getch();				/* get the key */
		}
	}
}

bool WaitForEnterOrESC()
{    
	int  ch1;
	bool KeyFound=false;
    do
	{
		ch1 = -1;
		if (_kbhit())					/* check for a keystroke */
		{
			ch1 = _getch();				/* get the key */
			if(ch1 == 13)
				KeyFound = true;
			else if(ch1 == 27)
				KeyFound = true;
		}
	}while(!KeyFound);
	if(ch1 == 13)
		return  true;
	else
		return  false;
}

char getArrowKey()
{
    int  ch1,ch2;
	bool KeyFound=false;
    
	do
	{
		ch1 = -1;
		ch2 = 'N';

		if (_kbhit())					/* check for a keystroke */
		{
			ch1 = _getch();				/* get the key */
			if (ch1==224)
			{
				ch2 = _getch();				/* get the next key */
				switch (ch2)
				{
				case 72:
					return	'U';	// up
				case 80:
					return	'D';	// down
				case 75:
					return	'L';	// left
				case 77:
					return	'R';	// right
				}
			}
			else if (ch1==32)
				KeyFound = true;		
		}
	}while(!KeyFound);
	return (char)ch1;
}

unsigned char wait4key()
{
	unsigned char  ch;
    
    ch = 0;
	while(!ch)
	{
		if (_kbhit())					/* check for a keystroke */
		{
			ch = (unsigned char)_getch();				/* get the key */
			if(ch == 224) //if its special key (arrow), ignore it
			{
				ch = (unsigned char)_getch(); //read the next ascii and dont use it
				ch=0;
			}
		}
	}
	return ch;
}